<?php
/**
 * Created by PhpStorm.
 * User: u
 * Date: 2018/11/29
 * Time: 16:55
 */

namespace app\controllers;

use common\logics\adminuser\AdminUserLogic;
use Yii;


class AdminController extends BaseController
{
    /** @var \common\logics\adminuser\AdminUserLogic $AdminUserService ***/
    private $AdminUserService;
    /**@var \common\logics\auth\AuthLogic $AuthService */
    private $AuthService;

    public function init()
    {
        $this->AuthService = Yii::$container->get("AuthService");
        $this->AdminUserService = Yii::$container->get('AdminUserService');
        return parent::init(); // TODO: Change the autogenerated stub
    }

    public function actionSign()
    {
        $param = [
            'phone' => Yii::$app->request->post('phone',''),//用户名
            "sms_code" => Yii::$app->request->post("sms_code",""),//验证码
        ];
        $result = $this->AdminUserService->getAdminUser($param);
        return$result;
    }

    //获取管理员列表
    public function actionGetList()
    {
        $result = $this->AdminUserService->getList();
        return $result;
    }

    //添加
    public function actionAddLoginUser()
    {
        $param = [
            "account"=> Yii::$app->request->post("account",''),                 //账号
            "username" => Yii::$app->request->post("username",""),              //姓名
            "email" => Yii::$app->request->post("email",''),                    //邮箱
            "role" => Yii::$app->request->post("role",''),                      //角色
        ];
        $result = $this->AdminUserService->addLoginUser($param);
        return $result;
    }
    //修改
    public function actionModifyLoginUser()
    {
        $param = [
            "login_id" => Yii::$app->request->post("login_id",""),              //登陆用户id
            "username" => Yii::$app->request->post("username",''),                    //邮箱
            "email" => Yii::$app->request->post("email",''),                    //邮箱
            "role" => Yii::$app->request->post("role",""),              //角色
        ];
        $result = $this->AdminUserService->modifyLoginUser($param);
        return $result;
    }
    //删除
    public function actionDelLoginUser()
    {
        $param = [
            "login_id" => Yii::$app->request->post("login_id",""),              //登陆用户id
            "safetyCode" => Yii::$app->request->post("safetyCode",""),          //安全码
        ];
        $result = $this->AdminUserService->delLoginUser($param);
        return $result;
    }

    //发送钉钉验证码
    public function actionSendDdCode()
    {
        $param = [
            'phone' => Yii::$app->request->post("phone",''),                  //手机号
            'content' => Yii::$app->request->post("content",''),                //备注内容
            "operator" => Yii::$app->request->post("operator",''),              //操作人或者登陆收件
        ];
        $result = $this->AdminUserService->sendDD($param);
        return $result;
    }
}